package multiThread;

// Thread life cycle
/*
 * This program displays the implimentation of multithread concept.
 * two threads are started.
 * the output of the two methods is sequence of numbers along with the thread name.
 * the thread is made to pause for 1 sec in between the output of each thread.
 */

class Ay implements Runnable {
	public void run() {
		for (int i = 0; i < 30; i++) {
			System.out.println(Thread.currentThread().getName() + " I = " + i);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
		}
	}
}

class By implements Runnable {
	public void run() {
		Thread t = Thread.currentThread();
		String name = t.getName();
		for (int i = 0; i < 20; i++) {
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
			}
			System.out.println(name + " J = " + i);
		}
	}

}

public class MyThread4 {
	public static void main(String args[]) {
		Ay obj1 = new Ay();
		By obj2 = new By();
		// Creation of thread.
		Thread t1 = new Thread(obj1);
		Thread t2 = new Thread(obj2);

		// Check for Thread alive
		System.out.println(t1.isAlive());
		System.out.println(t2.isAlive());
		System.out.println(Thread.currentThread().isAlive());

		// Thread is made runnable.
		t1.start();
		t2.start();

		// Check for Thread alive
		System.out.println(t1.isAlive());
		System.out.println(t2.isAlive());
		System.out.println(Thread.currentThread().isAlive());
	}
}